
//
// 110109 - AH - (Hector) Created.
// 110111 - AH - Removed refresh button, no longer needed now that
//               RetrievalEventTreeModel is a RetrievalPerformedEventListener
//               listener to SoekratEngine.
// 110111 - AH - (Fantoft) Now RetrievalEventTree is fetched from SoekratEngine 
//               not the Wheel.
// 110118 - AH - (Bien *) Took in use RetrievalEventCellRenderer.
// 110119 - AH - (Hector) Now expands trees when new RetrievalEvent sequence
//               been added (that was a fucking disaster).
//

package org.soekrat.gui.swing.retrieval;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;

import org.soekrat.engine.Soekrat2Engine;
import org.soekrat.engine.wheel.retrieval.RetrievalEventTree;

/**
 * <p>
 *   Shows a 
 *   {@link RetrievalEventTree} in a
 *   {@link JTree}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
@SuppressWarnings("serial")
public final class RetrievalEventTreePanel extends JPanel 
{
  private RetrievalEventTreeModel m_model; // TODO make final later.
  
  private final Soekrat2Engine m_engine;
  
  private final JTree m_tree;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param engine Engine interfaced.
   */
  public RetrievalEventTreePanel(Soekrat2Engine engine)
  {
    if (engine==null)
    {
      throw new NullPointerException("engine");
    }
    
    m_engine=engine;
    m_model=new RetrievalEventTreeModel(engine.getRetrievalEventTree());
    
    setLayout(new BorderLayout());
    
    m_tree=new JTree(m_model);
    m_tree.setCellRenderer(RetrievalEventCellRenderer.INSTANCE);
    m_tree.setRootVisible(false);
    add(new JScrollPane(m_tree));
    
    m_engine.addRetrievalPerformedEventListener(m_model);
    
    m_model.setGTree(this);
  }
  
  void changed()
  { 
    int row=0;
    while (row<m_tree.getRowCount()) 
    {
      m_tree.expandRow(row);
      row++;
    }
  }
  
}
